package me.king.mybatis.component.biz;

import java.util.List;

import org.apache.ibatis.session.SqlSession;

public class BaseServiceTemplate<T> implements IBaseService<T> {

	private SqlSession session;
	
	private String makeName(Class<?> cls, String method) {
		return cls.getName() + "." + method;
	}
	
	@Override
	public void save(Class<?> cls, String method, T t) {
		session.insert(makeName(cls, method),t);
	}

	@Override
	public void delete(Class<?> cls, String method, int id) {
		session.delete(makeName(cls, method), id);
	}

	@Override
	public void update(Class<?> cls, String method, T t) {
		session.update(makeName(cls, method),t);
	}

	@Override
	public SqlSession getSession() {
		return session;
	}

	public void setSession(SqlSession session) {
		this.session = session;
	}

	@Override
	public List<T> select(Class<?> cls, String method, T t) {
		return session.selectList(makeName(cls, method), t);
	}

	@Override
	public Object selectSingle(Class<?> cls, String method, T t) {
		return session.selectOne(makeName(cls, method), t);
	}

}
